<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core">

    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputText value="#{bundle.ListExpensesTitle}"></h:outputText>
        </ui:define>
        <ui:define name="body">
            <h:outputScript name="js/jsfunctions.js" />
            <h:form id="form">
                <h:panelGroup id="messagePanel" layout="block">
                    <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
                </h:panelGroup>
                
                <h:panelGrid>
                    <h:outputLabel value="#{bundle.Expense_From_Date}"/>
                    <p:calendar value="#{expensesController.fromDate}" id="fromDate" showOn="button" />
                    <h:outputLabel value="#{bundle.Expense_To_Date}"/>
                    <p:calendar value="#{expensesController.toDate}" id="toDate" showOn="button" />
                </h:panelGrid>
                    <h:commandButton action="#{expensesController.getExpenses}" value="#{bundle.GetEmployeeExpenses}" type="submit" />
                
                <h:panelGroup rendered="#{expensesController.searchItems.rowCount > 0}">
                    <h:outputText value="#{expensesController.expensesPagination.pageFirstItem + 1}..#{expensesController.expensesPagination.pageLastItem + 1}/#{expensesController.expensesPagination.itemsCount}"/>&nbsp;
                    <h:commandLink action="#{expensesController.previous}" value="#{bundle.Previous} #{expensesController.expensesPagination.pageSize}" rendered="#{expensesController.expensesPagination.hasPreviousPage}"/>&nbsp;
                    <h:commandLink action="#{expensesController.next}" value="#{bundle.Next} #{expensesController.expensesPagination.pageSize}" rendered="#{expensesController.expensesPagination.hasNextPage}"/>&nbsp;
                    <h:dataTable id="mytable" value="#{expensesController.searchItems}" var="item" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px">
                        
                        <h:column>
                            <f:facet name="header">
                                <h:selectBooleanCheckbox onchange='SelectAllCheckboxesSpecific(this)'/>
                            </f:facet>
                            <h:selectBooleanCheckbox  value="#{expensesController.checked[item.expId]}"/>
                        </h:column>
                        
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_expenseDate}"/>
                            </f:facet>
                            <h:outputText value="#{item.expenseDate}">
                                <f:convertDateTime pattern="MM/dd/yyyy" />
                            </h:outputText>
                        </h:column>
                        
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_project}"/>
                            </f:facet>
                            <h:outputText value="#{item.project.projectName}"/>
                        </h:column>
                        
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_task}"/>
                            </f:facet>
                            <h:outputText value="#{item.task}"/>
                        </h:column>
                        
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_expenseType}"/>
                            </f:facet>
                            <h:outputText value="#{item.expenseType}"/>
                        </h:column>
                        
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_comment}"/>
                            </f:facet>
                            <h:outputText value="#{item.comment}"/>
                        </h:column>
                        
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_reimbursable}"/>
                            </f:facet>
                            <h:outputText value="#{item.reimbursable}"/>
                        </h:column>
                        
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_units}"/>
                            </f:facet>
                            <h:outputText value="#{item.units}"/>
                        </h:column>
                        
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_currency}"/>
                            </f:facet>
                            <h:outputText value="#{item.currency.currencyCode}"/>
                        </h:column>
                        
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_expenseAmount}"/>
                            </f:facet>
                            <h:outputText value="#{item.expenseAmount}"/>
                        </h:column>
                        
                        <h:column rendered="${type=='admin'}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_employee}"/>
                            </f:facet>
                            <h:outputText value="#{item.employee.businessEmail}"/>
                        </h:column>
                        
                        <h:column rendered="${type=='admin'}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_createdAt}"/>
                            </f:facet>
                            <h:outputText value="#{item.createdAt}">
                                <f:convertDateTime pattern="MM/dd/yyyy" />
                            </h:outputText>
                        </h:column>
                        
                        <h:column rendered="${type=='admin'}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_createdBy}"/>
                            </f:facet>
                            <h:outputText value="#{item.createdBy.businessEmail}"/>
                        </h:column>
                        
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_expenseTotal}"/>
                            </f:facet>
                            <h:outputText value="#{item.expenseTotal}"/>
                        </h:column>
                        
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_status}"/>
                            </f:facet>
                            <h:outputText value="#{item.status}"/>
                        </h:column>
                        
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="&nbsp;"/>
                            </f:facet>
                            <h:commandLink action="#{expensesController.prepareView}" value="#{bundle.ListExpensesViewLink}"/>
                            <h:outputText value=" "/>
                            <h:commandLink rendered="#{item.status != 'submitted'}" action="#{expensesController.prepareEdit}" value="#{bundle.ListExpensesEditLink}"/>
                        </h:column>
                    </h:dataTable>
                </h:panelGroup>
                <br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <h:commandButton action="#{expensesController.prepareCreate}" type="submit" value="#{bundle.ListExpensesCreateLink}"/>
                <h:commandButton value="Delete" action="#{expensesController.deleteSelected}" />
                <h:commandButton value="Submit" action="#{expensesController.submitSelected}" />
                <h:button rendered="${type=='admin'}" value="Back to Home" outcome="/index"/>
                <h:button rendered="${type=='user'}" value="Back to Home" outcome="/userhome"/>
            </h:form>
        </ui:define>
    </ui:composition>
</html>